package cn.weiyang.model;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.Min;
import javax.validation.executable.ValidateOnExecution;

/**
 * 对用户属性进行校验
 * Created by Administrator on 2017/7/27.
 */
public class User {
    @NotEmpty(message = "用户名不能为空")
    private String username;
    /*参数校验可以用group接口实现不同的校验*/
    @Length(min = 6,max = 10,message = "密码必须为6-10位",groups=GroupA.class)
    @NotEmpty(message = "密码不能为空",groups=GroupB.class)
    private String password;
    @Min(value = 18,message = "年龄至少18岁")
    private int age;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public interface GroupA{}
    public interface GroupB{}
}
